# -*- coding: utf-8 -*-
from selenium import webdriver  # 爱问共享资料
from lxml import etree


def analysis(html):
    us = etree.HTML(html).xpath('//*[@id="office-tab-box"]/div/div[1]/div[3]/ul/li/h4/a')
    for u in us:
        url = 'http://ishare.iask.sina.com.cn' + u.xpath('@href')[0]
        print(url)


def rebder(text, t):
    url_list = []
    driver = webdriver.PhantomJS()
    driver.get('http://ishare.iask.sina.com.cn/')
    driver.find_element_by_id("scondition").send_keys(text)
    driver.find_element_by_id("searchBtn").click()
    for i in range(t):
        html = driver.page_source
        analysis(html)
        driver.find_element_by_link_text("下一页").click()
        driver.save_screenshot(str(i) + ".png")

    driver.close()


if __name__ == "__main__":
    text = input("请输入您想搜索的内容:")
    t = int(input("请输入您想下载的页面数:"))
    rebder(text, t)
